package MyTest;

import java.util.Scanner;

public class TestDemo3 {
    volatile public static int flag = 0;//volatile修饰自定义标志位
    public static void main(String[] args) {
        Thread thread1 = new Thread(()-> {
            while (flag == 0) {
                //空
            }
            System.out.println("thread1线程结束");
        });//线程1

        Thread thread2 = new Thread(()-> {
            Scanner scanner = new Scanner(System.in);
            System.out.println("请输入一个整数:");
            flag = scanner.nextInt();
        });//线程2

        thread1.start();//启动线程1
        thread2.start();//启动线程2
    }
}
